<!DOCTYPE html>
<html lang="zh-hans">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 5.3.0">


  <link rel="apple-touch-icon" sizes="180x180" href="/wow/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/wow/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/wow/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/wow/images/logo.svg" color="#222">

<link rel="stylesheet" href="/wow/css/main.css">



<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@5.15.3/css/all.min.css">
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/animate.css@3.1.1/animate.min.css">

<script class="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"single-flower.gitee.io","root":"/wow/","images":"/wow/images","scheme":"Muse","version":"8.3.0","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12},"copycode":false,"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"fadeInDown","post_body":"fadeInDown","coll_header":"fadeInLeft","sidebar":"fadeInUp"}},"prism":false,"i18n":{"placeholder":"بحث...","empty":"We didn't find any results for the search: ${query}","hits_time":"${hits} results found in ${time} ms","hits":"${hits} results found"}};
  </script>
<meta property="og:type" content="website">
<meta property="og:title" content="朵朵最可爱">
<meta property="og:url" content="https://single-flower.gitee.io/wow/index.html">
<meta property="og:site_name" content="朵朵最可爱">
<meta property="og:locale">
<meta property="article:author" content="X y">
<meta name="twitter:card" content="summary">


<link rel="canonical" href="https://single-flower.gitee.io/wow/">


<script class="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : true,
    isPost : false,
    lang   : 'zh-hans'
  };
</script>
<title>朵朵最可爱</title>
  




  <noscript>
  <style>
  body { margin-top: 2rem; }

  .use-motion .menu-item,
  .use-motion .sidebar,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header {
    visibility: visible;
  }

  .use-motion .header,
  .use-motion .site-brand-container .toggle,
  .use-motion .footer { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle,
  .use-motion .custom-logo-image {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line {
    transform: scaleX(1);
  }

  .search-pop-overlay, .sidebar-nav { display: none; }
  .sidebar-panel { display: block; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage" class="use-motion">
  <div class="headband"></div>

  <main class="main">
    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="تشغيل شريط التصفح" role="button">
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/wow/" class="brand" rel="start">
      <i class="logo-line"></i>
      <h1 class="site-title">朵朵最可爱</h1>
      <i class="logo-line"></i>
    </a>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
    </div>
  </div>
</div>



<nav class="site-nav">
  <ul class="main-menu menu">
        <li class="menu-item menu-item-home"><a href="/wow/" rel="section"><i class="fa fa-home fa-fw"></i>Home</a></li>
        <li class="menu-item menu-item-about"><a href="/wow/about/" rel="section"><i class="fa fa-user fa-fw"></i>معلومات</a></li>
        <li class="menu-item menu-item-tags"><a href="/wow/tags/" rel="section"><i class="fa fa-tags fa-fw"></i>الوسوم</a></li>
        <li class="menu-item menu-item-categories"><a href="/wow/categories/" rel="section"><i class="fa fa-th fa-fw"></i>التصنيفات</a></li>
        <li class="menu-item menu-item-archives"><a href="/wow/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>الأرشيفات</a></li>
  </ul>
</nav>




</div>
        
  
  <div class="toggle sidebar-toggle" role="button">
    <span class="toggle-line"></span>
    <span class="toggle-line"></span>
    <span class="toggle-line"></span>
  </div>

  <aside class="sidebar">

    <div class="sidebar-inner sidebar-overview-active">
      <ul class="sidebar-nav">
        <li class="sidebar-nav-toc">
          المحتويات
        </li>
        <li class="sidebar-nav-overview">
          عام
        </li>
      </ul>

      <div class="sidebar-panel-container">
        <!--noindex-->
        <div class="post-toc-wrap sidebar-panel">
        </div>
        <!--/noindex-->

        <div class="site-overview-wrap sidebar-panel">
          <div class="site-author site-overview-item animated" itemprop="author" itemscope itemtype="http://schema.org/Person">
  <p class="site-author-name" itemprop="name">X y</p>
  <div class="site-description" itemprop="description"></div>
</div>
<div class="site-state-wrap site-overview-item animated">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/wow/archives/">
        
          <span class="site-state-item-count">23</span>
          <span class="site-state-item-name">المقالات</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
        <span class="site-state-item-count">1</span>
        <span class="site-state-item-name">التصنيفات</span>
      </div>
      <div class="site-state-item site-state-tags">
        <span class="site-state-item-count">1</span>
        <span class="site-state-item-name">الوسوم</span>
      </div>
  </nav>
</div>



        </div>
      </div>
    </div>
  </aside>
  <div class="sidebar-dimmer"></div>


    </header>

    
  <div class="back-to-top" role="button" aria-label="Back to top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>

<noscript>
  <div class="noscript-warning">Theme NexT works best with JavaScript enabled</div>
</noscript>


    <div class="main-inner index posts-expand">

    


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="">
    <link itemprop="mainEntityOfPage" href="https://single-flower.gitee.io/wow/2021/04/15/SD/%E9%9D%A2%E8%AF%95%E9%A2%98_%E5%86%85%E7%BD%AE%E6%A8%A1%E5%9D%978/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/wow/images/avatar.gif">
      <meta itemprop="name" content="X y">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="朵朵最可爱">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          <a href="/wow/2021/04/15/SD/%E9%9D%A2%E8%AF%95%E9%A2%98_%E5%86%85%E7%BD%AE%E6%A8%A1%E5%9D%978/" class="post-title-link" itemprop="url">内置模块8</a>
        </h2>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">نُشر في</span>

      <time title="أُنشأ: 2021-04-15 19:36:05" itemprop="dateCreated datePublished" datetime="2021-04-15T19:36:05+08:00">2021-04-15</time>
    </span>
      <span class="post-meta-item">
        <span class="post-meta-item-icon">
          <i class="far fa-calendar-check"></i>
        </span>
        <span class="post-meta-item-text">عُدل في</span>
        <time title="عُدل: 2021-04-16 07:41:48" itemprop="dateModified" datetime="2021-04-16T07:41:48+08:00">2021-04-16</time>
      </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">في</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/wow/categories/GIT/" itemprop="url" rel="index"><span itemprop="name">-GIT</span></a>
        </span>
    </span>

  
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
          <h3 id=""><a href="#" class="headerlink" title=""></a></h3><h3 id="-1"><a href="#-1" class="headerlink" title=""></a></h3><h3 id="-2"><a href="#-2" class="headerlink" title=""></a></h3><h3 id="-3"><a href="#-3" class="headerlink" title=""></a></h3><h3 id="-4"><a href="#-4" class="headerlink" title=""></a></h3><h2 id="正则模块："><a href="#正则模块：" class="headerlink" title="正则模块："></a>正则模块：</h2><pre><code>--由一系列特殊字符拼接而成的表达式/规则，
\w 匹配字母数字及下划线
\W 匹配非字母数字下划线
\s 匹配任意空白字符[\t\n\r\f]也算
\S 匹配非空白字符
\d 匹配任意数字 = [0-9]
\D 匹配任意非数字
^ 匹配字符串的开头
&amp; 匹配字符串的结尾
[] 用来匹配一个字符，我们可以指定其范围</code></pre>
<h2 id="贪婪和非贪婪"><a href="#贪婪和非贪婪" class="headerlink" title="贪婪和非贪婪:"></a>贪婪和非贪婪:</h2><pre><code>--  .*  : 匹配所有 （计算到字符串结束）</code></pre>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">print(re.findall(<span class="string">&quot;a.*b&quot;</span>,<span class="string">&quot;123 a1231-==-000b123123123123123b&quot;</span>))</span><br><span class="line">[<span class="string">&#x27;a1231-==-000b123123123123123b&#x27;</span>]</span><br></pre></td></tr></table></figure>
<pre><code>    .*? : 为非贪婪匹配：（即得到符合结果就返回）</code></pre>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">print(re.findall(<span class="string">&quot;a.*?b&quot;</span>,<span class="string">&quot;123 a1231-==-000b123123123123123b&quot;</span>))</span><br><span class="line">[<span class="string">&#x27;a1231-==-000b&#x27;</span>]</span><br></pre></td></tr></table></figure>
<h2 id="正则匹配手机号："><a href="#正则匹配手机号：" class="headerlink" title="正则匹配手机号："></a>正则匹配手机号：</h2><pre><code>--</code></pre>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> re</span><br><span class="line">phone_number=input(<span class="string">&#x27;请输入你的电话号码：&#x27;</span>)</span><br><span class="line"><span class="keyword">if</span> re.match(<span class="string">&#x27;^(13|14|15|17|18)[0-9]&#123;9&#125;$&#x27;</span>,phone_number):</span><br><span class="line">    <span class="string">&#x27;&#x27;</span><span class="string">&#x27;^这个符号表示的是判断是不是以13|14|15|17|18开头的，</span></span><br><span class="line"><span class="string">    [0-9]: []表示一个字符组，可以表示0-9的任意字符</span></span><br><span class="line"><span class="string">    &#123;9&#125;:表示后面的数字重复九次</span></span><br><span class="line"><span class="string">    $:表示结束符</span></span><br><span class="line"><span class="string">    &#x27;</span><span class="string">&#x27;&#x27;</span></span><br><span class="line">    print(<span class="string">&#x27;是合法的手机号码&#x27;</span>)</span><br><span class="line"><span class="keyword">else</span>:</span><br><span class="line">    print(<span class="string">&#x27;不是合法的手机号码&#x27;</span>)</span><br></pre></td></tr></table></figure>
<h2 id="："><a href="#：" class="headerlink" title="："></a>：</h2><pre><code>--</code></pre>
<h2 id="：-1"><a href="#：-1" class="headerlink" title="："></a>：</h2><pre><code>--</code></pre>

      
    </div>

    
    
    

    <footer class="post-footer">
        <div class="post-eof"></div>
      
    </footer>
  </article>
</div>




    


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="">
    <link itemprop="mainEntityOfPage" href="https://single-flower.gitee.io/wow/2021/04/13/SD/%E9%9D%A2%E8%AF%95%E9%A2%98_%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B3/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/wow/images/avatar.gif">
      <meta itemprop="name" content="X y">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="朵朵最可爱">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          <a href="/wow/2021/04/13/SD/%E9%9D%A2%E8%AF%95%E9%A2%98_%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B3/" class="post-title-link" itemprop="url">数据类型3</a>
        </h2>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">نُشر في</span>

      <time title="أُنشأ: 2021-04-13 18:44:31" itemprop="dateCreated datePublished" datetime="2021-04-13T18:44:31+08:00">2021-04-13</time>
    </span>
      <span class="post-meta-item">
        <span class="post-meta-item-icon">
          <i class="far fa-calendar-check"></i>
        </span>
        <span class="post-meta-item-text">عُدل في</span>
        <time title="عُدل: 2021-04-14 20:53:50" itemprop="dateModified" datetime="2021-04-14T20:53:50+08:00">2021-04-14</time>
      </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">في</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/wow/categories/GIT/" itemprop="url" rel="index"><span itemprop="name">-GIT</span></a>
        </span>
    </span>

  
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
          <h3 id="可变不可变数据类型"><a href="#可变不可变数据类型" class="headerlink" title="可变不可变数据类型"></a>可变不可变数据类型</h3><h3 id="列表和元组之间的区别"><a href="#列表和元组之间的区别" class="headerlink" title="列表和元组之间的区别"></a>列表和元组之间的区别</h3><h3 id="字典的底层"><a href="#字典的底层" class="headerlink" title="字典的底层"></a>字典的底层</h3><h3 id="开放寻址法"><a href="#开放寻址法" class="headerlink" title="开放寻址法"></a>开放寻址法</h3><h2 id="可变不可变数据类型："><a href="#可变不可变数据类型：" class="headerlink" title="可变不可变数据类型："></a>可变不可变数据类型：</h2><pre><code>--可变数据类型：列表、集合、字典
--不可变数据类型：数字、字符串、元组、不可变集合</code></pre>
<h2 id="列表和元组之间的区别："><a href="#列表和元组之间的区别：" class="headerlink" title="列表和元组之间的区别："></a>列表和元组之间的区别：</h2><pre><code>--列表中的元素可以进行任意修改，就好比铅笔在纸上写的字，写错了还能重写，--而元组中的元素就无法修改了。</code></pre>
<h2 id="字典的底层："><a href="#字典的底层：" class="headerlink" title="字典的底层："></a>字典的底层：</h2><pre><code>--Cpython使用伪随机探测的散列表作为字典底层数据结构。只有哈希对象才能作为键。
--Py中所有不可变的内置类型都是可哈希的。
--可变类型（列表，字典，集合）不可哈希的。</code></pre>
<h2 id="开放寻址法："><a href="#开放寻址法：" class="headerlink" title="开放寻址法："></a>开放寻址法：</h2><pre><code>一间厕所，来了一个顾客就蹲其对应的位置，如果又来了一个顾客，把厕所单间门打开，一看里面有人，那怎么办？很自然，拉开另一个单间的门，看有没有人，有的话继续找坑。这个顾客不会按顺序一个一个地拉厕所门，而是会去拉他所认为有可能没有被占用的坑的门。通过闻，听来辨别，这就是开放寻址法。</code></pre>

      
    </div>

    
    
    

    <footer class="post-footer">
        <div class="post-eof"></div>
      
    </footer>
  </article>
</div>




    


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="">
    <link itemprop="mainEntityOfPage" href="https://single-flower.gitee.io/wow/2021/04/13/SD/%E9%9D%A2%E8%AF%95%E9%A2%98_%E5%87%BD%E6%95%B0%E5%9F%BA%E7%A1%806/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/wow/images/avatar.gif">
      <meta itemprop="name" content="X y">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="朵朵最可爱">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          <a href="/wow/2021/04/13/SD/%E9%9D%A2%E8%AF%95%E9%A2%98_%E5%87%BD%E6%95%B0%E5%9F%BA%E7%A1%806/" class="post-title-link" itemprop="url">函数基础6</a>
        </h2>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">نُشر في</span>

      <time title="أُنشأ: 2021-04-13 18:39:12" itemprop="dateCreated datePublished" datetime="2021-04-13T18:39:12+08:00">2021-04-13</time>
    </span>
      <span class="post-meta-item">
        <span class="post-meta-item-icon">
          <i class="far fa-calendar-check"></i>
        </span>
        <span class="post-meta-item-text">عُدل في</span>
        <time title="عُدل: 2021-04-15 07:55:39" itemprop="dateModified" datetime="2021-04-15T07:55:39+08:00">2021-04-15</time>
      </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">في</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/wow/categories/GIT/" itemprop="url" rel="index"><span itemprop="name">-GIT</span></a>
        </span>
    </span>

  
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
          <h3 id="python内置的高阶方法"><a href="#python内置的高阶方法" class="headerlink" title="python内置的高阶方法"></a>python内置的高阶方法</h3><h3 id="lambda表达式以及跳转表"><a href="#lambda表达式以及跳转表" class="headerlink" title="lambda表达式以及跳转表"></a>lambda表达式以及跳转表</h3><h3 id="不定长参数如何使用"><a href="#不定长参数如何使用" class="headerlink" title="不定长参数如何使用"></a>不定长参数如何使用</h3><h3 id="pass"><a href="#pass" class="headerlink" title="pass"></a>pass</h3><h3 id="global和nonlocal的作用"><a href="#global和nonlocal的作用" class="headerlink" title="global和nonlocal的作用"></a>global和nonlocal的作用</h3><h2 id="python内置的高阶方法："><a href="#python内置的高阶方法：" class="headerlink" title="python内置的高阶方法："></a>python内置的高阶方法：</h2><p>   map()</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">def add(x):</span><br><span class="line">    <span class="keyword">return</span> x+x</span><br><span class="line"></span><br><span class="line">print(map(add,[<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>]))</span><br><span class="line"><span class="comment">//Out:&lt;map object at 0x00000239E833DE48&gt;</span></span><br><span class="line">print(list(map(add,[<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>])))</span><br><span class="line"><span class="comment">//Out:[2,4,6]</span></span><br></pre></td></tr></table></figure>

<h2 id="lambda表达式以及跳转表-1"><a href="#lambda表达式以及跳转表-1" class="headerlink" title="lambda表达式以及跳转表:"></a>lambda表达式以及跳转表:</h2><pre><code>--lambda</code></pre>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">add = lambda x, <span class="attr">y</span> : x+y</span><br><span class="line"></span><br><span class="line">add(<span class="number">1</span>,<span class="number">2</span>) <span class="comment">//结果为3</span></span><br></pre></td></tr></table></figure>
<pre><code>--跳跃表是为了解决平衡树插入或者删除操作过于复杂而进行设计的
跳跃表有如下特点：

(1) 每个跳跃表由很多层结构组成；
(2) 每一层都是一个有序链表，且第一个节点是头节点；
(3) 最底层的有序链表包含所有节点；
(4) 每个节点可能有多个指针，这与节点所包含的层数有关；
(5) 跳跃表的查找、插入、删除的时间复杂度均为O(log N)。</code></pre>
<h2 id="不定长参数如何使用："><a href="#不定长参数如何使用：" class="headerlink" title="不定长参数如何使用："></a>不定长参数如何使用：</h2><pre><code>--*args接收单个出现的参数，接收后存为元组
--**kwargs接收以键值对形式出现的参数，接收后存为一个字典</code></pre>
<h2 id="pass："><a href="#pass：" class="headerlink" title="pass："></a>pass：</h2><pre><code>--空语句  占位的作用</code></pre>
<h2 id="global和nonlocal的作用："><a href="#global和nonlocal的作用：" class="headerlink" title="global和nonlocal的作用："></a>global和nonlocal的作用：</h2><pre><code>--global是全局变量，用在任何地方</code></pre>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//如果未使用 </span></span><br><span class="line">x = <span class="number">1</span></span><br><span class="line"> </span><br><span class="line">def func():k<span class="string">&#x27;b&#x27;</span>h</span><br><span class="line">    x = <span class="number">2</span></span><br><span class="line"> </span><br><span class="line">func()</span><br><span class="line">print(x)       <span class="comment">//1</span></span><br><span class="line"></span><br><span class="line"><span class="comment">//使用了</span></span><br><span class="line">x = <span class="number">1</span>      </span><br><span class="line"> </span><br><span class="line">def func():</span><br><span class="line">    <span class="built_in">global</span> x</span><br><span class="line">    x = <span class="number">2</span></span><br><span class="line"> </span><br><span class="line">func()</span><br><span class="line">print(x)      <span class="comment">//2</span></span><br></pre></td></tr></table></figure>
<pre><code>nonlocal是上一级函数中的局部变量，只能用在嵌套函数中</code></pre>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">def b():</span><br><span class="line">  num2=<span class="number">1</span></span><br><span class="line">  def c():</span><br><span class="line">   nonlocal num2    <span class="comment">//为了修改非全局变量</span></span><br><span class="line">   num2+=<span class="number">2</span></span><br><span class="line">   print(num2)</span><br><span class="line">  <span class="keyword">return</span> c</span><br><span class="line">b()()</span><br></pre></td></tr></table></figure>






      
    </div>

    
    
    

    <footer class="post-footer">
        <div class="post-eof"></div>
      
    </footer>
  </article>
</div>




    


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="">
    <link itemprop="mainEntityOfPage" href="https://single-flower.gitee.io/wow/2021/04/13/SD/%E9%9D%A2%E8%AF%95%E9%A2%98_%E9%9D%A2%E5%90%91%E5%AF%B9%E8%B1%A19/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/wow/images/avatar.gif">
      <meta itemprop="name" content="X y">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="朵朵最可爱">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          <a href="/wow/2021/04/13/SD/%E9%9D%A2%E8%AF%95%E9%A2%98_%E9%9D%A2%E5%90%91%E5%AF%B9%E8%B1%A19/" class="post-title-link" itemprop="url">面向对象9</a>
        </h2>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">نُشر في</span>

      <time title="أُنشأ: 2021-04-13 14:15:03" itemprop="dateCreated datePublished" datetime="2021-04-13T14:15:03+08:00">2021-04-13</time>
    </span>
      <span class="post-meta-item">
        <span class="post-meta-item-icon">
          <i class="far fa-calendar-check"></i>
        </span>
        <span class="post-meta-item-text">عُدل في</span>
        <time title="عُدل: 2021-04-15 21:14:06" itemprop="dateModified" datetime="2021-04-15T21:14:06+08:00">2021-04-15</time>
      </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">في</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/wow/categories/GIT/" itemprop="url" rel="index"><span itemprop="name">-GIT</span></a>
        </span>
    </span>

  
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
          <h3 id="什么是面向过程和面向对象"><a href="#什么是面向过程和面向对象" class="headerlink" title="什么是面向过程和面向对象"></a>什么是面向过程和面向对象</h3><h3 id="面向对象三要素"><a href="#面向对象三要素" class="headerlink" title="面向对象三要素"></a>面向对象三要素</h3><h3 id="面向对象五大原则"><a href="#面向对象五大原则" class="headerlink" title="面向对象五大原则"></a>面向对象五大原则</h3><h3 id="面向对象的mro"><a href="#面向对象的mro" class="headerlink" title="面向对象的mro"></a>面向对象的mro</h3><h3 id="super-方法"><a href="#super-方法" class="headerlink" title="super()方法"></a>super()方法</h3><h3 id="self指针"><a href="#self指针" class="headerlink" title="self指针"></a>self指针</h3><h3 id="isinstance方法"><a href="#isinstance方法" class="headerlink" title="isinstance方法"></a>isinstance方法</h3><h3 id="python中的魔法方法"><a href="#python中的魔法方法" class="headerlink" title="python中的魔法方法"></a>python中的魔法方法</h3><h3 id="特殊的魔法方法"><a href="#特殊的魔法方法" class="headerlink" title="特殊的魔法方法"></a>特殊的魔法方法</h3><h3 id="静态，类方法的区别"><a href="#静态，类方法的区别" class="headerlink" title="静态，类方法的区别"></a>静态，类方法的区别</h3><h3 id="类中装饰器property"><a href="#类中装饰器property" class="headerlink" title="类中装饰器property"></a>类中装饰器property</h3><h3 id="元类"><a href="#元类" class="headerlink" title="元类"></a>元类</h3><h3 id="反射"><a href="#反射" class="headerlink" title="反射"></a>反射</h3><h3 id="猴子补丁"><a href="#猴子补丁" class="headerlink" title="猴子补丁"></a>猴子补丁</h3><h3 id="什么是面向过程和面向对象-1"><a href="#什么是面向过程和面向对象-1" class="headerlink" title="什么是面向过程和面向对象"></a>什么是面向过程和面向对象</h3><pre><code>--有一天你想吃鱼香肉丝了，怎么办呢？你有两个选择
1、自己买材料，肉，鱼香肉丝调料，蒜苔，胡萝卜等等然后切菜切肉，开炒，盛到盘子里。
2、去饭店，张开嘴：老板！来一份鱼香肉丝！
看出来区别了吗？1是面向过程2是面向对象(优势就是降低耦合，提高维护性)</code></pre>
<h2 id="面向对象三要素-1"><a href="#面向对象三要素-1" class="headerlink" title="面向对象三要素:"></a>面向对象三要素:</h2><pre><code>--1、封装
隐藏实现细节，使得代码模块化
封装的意义：在于保护或者防止代码被我们无意中破坏
2、继承
可以扩展已存在的代码模块-------目的代码重用
3、多态
一个接口，多种方法
接口重用</code></pre>
<h2 id="面向对象五大原则：了解三个即可"><a href="#面向对象五大原则：了解三个即可" class="headerlink" title="面向对象五大原则：了解三个即可"></a>面向对象五大原则：了解三个即可</h2><pre><code>--单一职责  原则   SRP
类的功能要单一，不能包罗万象，跟杂货铺似的。
--开放封闭  原则   OCP
一个模块对于拓展是开放的，对于修改是封闭的，想要增加功能热烈欢迎，想要修改，哼，一万个不乐意。
--里式替换  原则   LSP
子类可以替换父类出现在父类能够出现的任何地方。比如你能代表你爸去你姥姥家干活。哈哈~~</code></pre>
<h2 id="面向对象的mro："><a href="#面向对象的mro：" class="headerlink" title="面向对象的mro："></a>面向对象的mro：</h2><pre><code>--也就是继承查询顺序

--多继承时的顺序：
python2是深度优先  一条路走到底
python3是广度优先 先一条路走到倒数第二级 判断如果有别的路能走到终点 就返回</code></pre>
<h2 id="super-方法："><a href="#super-方法：" class="headerlink" title="super()方法："></a>super()方法：</h2><pre><code>--在子类中获取父类的一个方法
还可以解决多继承问题
好处就是可以避免直接使用父类的名字，主要用于多重继承


三个类 都有共同一个方法，第三个类中super().m 后  再调用第三个类
如果没有super()这个方法它就会再执行一个AB，有了就不用了  直接一遍即可</code></pre>
<h2 id="self指针："><a href="#self指针：" class="headerlink" title="self指针："></a>self指针：</h2><pre><code>--self代表类的实例，而非类</code></pre>
<p>self的用法</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">Test</span>:</span></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">prt</span>(<span class="params">self</span>):</span></span><br><span class="line">        print(self)</span><br><span class="line">        print(self.__class__)</span><br><span class="line"> </span><br><span class="line">t = Test()</span><br><span class="line">t.prt()</span><br></pre></td></tr></table></figure>
<p>执行结果如下</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">&lt;__main__.Test <span class="built_in">object</span> at <span class="number">0x000000000284E080</span>&gt;</span><br><span class="line">&lt;<span class="class"><span class="keyword">class</span> &#x27;<span class="title">__main__</span>.<span class="title">Test</span>&#x27;&gt;</span></span><br></pre></td></tr></table></figure>
<p>self不必非写成self     写成什么都一样</p>
<h2 id="isinstance方法："><a href="#isinstance方法：" class="headerlink" title="isinstance方法："></a>isinstance方法：</h2><pre><code>--类似于type</code></pre>
<h2 id="python中的魔法方法："><a href="#python中的魔法方法：" class="headerlink" title="python中的魔法方法："></a>python中的魔法方法：</h2><pre><code>--python中的魔法方法总是被双下划线__包围，比如：__init__()
魔法方法的魔法就体现在他们会在需要的时候被自动调用</code></pre>
<h2 id="特殊的魔法方法："><a href="#特殊的魔法方法：" class="headerlink" title="特殊的魔法方法："></a>特殊的魔法方法：</h2><h2 id="静态，类方法的区别："><a href="#静态，类方法的区别：" class="headerlink" title="静态，类方法的区别："></a>静态，类方法的区别：</h2><h2 id="类中装饰器property："><a href="#类中装饰器property：" class="headerlink" title="类中装饰器property："></a>类中装饰器property：</h2><h2 id="元类："><a href="#元类：" class="headerlink" title="元类："></a>元类：</h2><h2 id="反射："><a href="#反射：" class="headerlink" title="反射："></a>反射：</h2><h2 id="猴子补丁："><a href="#猴子补丁：" class="headerlink" title="猴子补丁："></a>猴子补丁：</h2>
      
    </div>

    
    
    

    <footer class="post-footer">
        <div class="post-eof"></div>
      
    </footer>
  </article>
</div>




    


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="">
    <link itemprop="mainEntityOfPage" href="https://single-flower.gitee.io/wow/2021/04/13/SD/%E9%9D%A2%E8%AF%95%E9%A2%98_%E5%87%BD%E6%95%B0%E8%BF%9B%E9%98%B67/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/wow/images/avatar.gif">
      <meta itemprop="name" content="X y">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="朵朵最可爱">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          <a href="/wow/2021/04/13/SD/%E9%9D%A2%E8%AF%95%E9%A2%98_%E5%87%BD%E6%95%B0%E8%BF%9B%E9%98%B67/" class="post-title-link" itemprop="url">函数进阶7</a>
        </h2>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">نُشر في</span>

      <time title="أُنشأ: 2021-04-13 08:46:17" itemprop="dateCreated datePublished" datetime="2021-04-13T08:46:17+08:00">2021-04-13</time>
    </span>
      <span class="post-meta-item">
        <span class="post-meta-item-icon">
          <i class="far fa-calendar-check"></i>
        </span>
        <span class="post-meta-item-text">عُدل في</span>
        <time title="عُدل: 2021-04-15 21:54:36" itemprop="dateModified" datetime="2021-04-15T21:54:36+08:00">2021-04-15</time>
      </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">في</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/wow/categories/GIT/" itemprop="url" rel="index"><span itemprop="name">-GIT</span></a>
        </span>
    </span>

  
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
          <h3 id="闭包"><a href="#闭包" class="headerlink" title="闭包"></a>闭包</h3><h3 id="装饰器"><a href="#装饰器" class="headerlink" title="装饰器"></a>装饰器</h3><h3 id="递归"><a href="#递归" class="headerlink" title="递归"></a>递归</h3><h3 id="递归实现斐波那契数列"><a href="#递归实现斐波那契数列" class="headerlink" title="递归实现斐波那契数列"></a>递归实现斐波那契数列</h3><h3 id="函数参数的传值传引用"><a href="#函数参数的传值传引用" class="headerlink" title="函数参数的传值传引用"></a>函数参数的传值传引用</h3><h2 id="闭包-1"><a href="#闭包-1" class="headerlink" title="闭包:"></a>闭包:</h2><pre><code>--闭包就是能够读取其他函数内部变量的函数。
在本质上，闭包是将函数内部和函数外部连接起来的桥梁。</code></pre>
<p>如何从外部读取函数内部的局部变量？<br>那就是在函数内部，再定义一个函数</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">f1</span>(<span class="params"></span>)</span>&#123;</span><br><span class="line">    <span class="keyword">var</span> n=<span class="number">999</span>;</span><br><span class="line">    <span class="function"><span class="keyword">function</span> <span class="title">f2</span>(<span class="params"></span>)</span>&#123;</span><br><span class="line">        alert(n); <span class="comment">// 999</span></span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">//在上面的代码中，函数 f2 就被包括在函数 f1 内部，这时 f1 内部的所有局部变量，对 f2 都是可见的。但是反过来就不行，f2 内部的局部变量，对 f1 就是不可见的</span></span><br></pre></td></tr></table></figure>
<p>f2就是闭包函数</p>
<h2 id="装饰器-1"><a href="#装饰器-1" class="headerlink" title="装饰器:"></a>装饰器:</h2><pre><code>--装饰器就是把一个猴子，塞入炼丹炉，然后就出来一个还是会吃桃子，但有火眼金睛的猴子；还是原来的猴子，但多了特效技能。</code></pre>
<h2 id="递归："><a href="#递归：" class="headerlink" title="递归："></a>递归：</h2><pre><code>--就是自己调用自己 体现出“以此类推”，“用同样的步骤重复”这样的思想</code></pre>
<h2 id="递归实现斐波那契数列："><a href="#递归实现斐波那契数列：" class="headerlink" title="递归实现斐波那契数列："></a>递归实现斐波那契数列：</h2><pre><code>--</code></pre>
<figure class="highlight"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">def fib(x):</span><br><span class="line">    <span class="keyword">if</span> x &lt; <span class="number">2</span>:</span><br><span class="line">        <span class="keyword">return</span> <span class="number">0</span> <span class="keyword">if</span> x == <span class="number">0</span> <span class="keyword">else</span> <span class="number">1</span></span><br><span class="line">    # 当x &gt; 2时，开始递归调用fib()函数:</span><br><span class="line">    <span class="keyword">return</span> fib(x - <span class="number">1</span>) + fib(x - <span class="number">2</span>)</span><br><span class="line"></span><br><span class="line">print(fib(6))  # 打印结果为:8</span><br></pre></td></tr></table></figure>
<h2 id="函数参数的传值传引用："><a href="#函数参数的传值传引用：" class="headerlink" title="函数参数的传值传引用："></a>函数参数的传值传引用：</h2><pre><code>-- </code></pre>

      
    </div>

    
    
    

    <footer class="post-footer">
        <div class="post-eof"></div>
      
    </footer>
  </article>
</div>




    


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="">
    <link itemprop="mainEntityOfPage" href="https://single-flower.gitee.io/wow/2021/04/12/SD/%E9%9D%A2%E8%AF%95%E9%A2%98_%E5%86%85%E5%AD%98%E7%AE%A1%E7%90%864/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/wow/images/avatar.gif">
      <meta itemprop="name" content="X y">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="朵朵最可爱">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          <a href="/wow/2021/04/12/SD/%E9%9D%A2%E8%AF%95%E9%A2%98_%E5%86%85%E5%AD%98%E7%AE%A1%E7%90%864/" class="post-title-link" itemprop="url">内存管理4</a>
        </h2>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">نُشر في</span>

      <time title="أُنشأ: 2021-04-12 15:07:28" itemprop="dateCreated datePublished" datetime="2021-04-12T15:07:28+08:00">2021-04-12</time>
    </span>
      <span class="post-meta-item">
        <span class="post-meta-item-icon">
          <i class="far fa-calendar-check"></i>
        </span>
        <span class="post-meta-item-text">عُدل في</span>
        <time title="عُدل: 2021-04-14 20:54:27" itemprop="dateModified" datetime="2021-04-14T20:54:27+08:00">2021-04-14</time>
      </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">في</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/wow/categories/GIT/" itemprop="url" rel="index"><span itemprop="name">-GIT</span></a>
        </span>
    </span>

  
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
          <h3 id="引用计数"><a href="#引用计数" class="headerlink" title="引用计数"></a>引用计数</h3><h3 id="如何使引用计数减少"><a href="#如何使引用计数减少" class="headerlink" title="如何使引用计数减少"></a>如何使引用计数减少</h3><h3 id="引用计数会导致什么问题"><a href="#引用计数会导致什么问题" class="headerlink" title="引用计数会导致什么问题"></a>引用计数会导致什么问题</h3><h3 id="那你还懂标记清除吗"><a href="#那你还懂标记清除吗" class="headerlink" title="那你还懂标记清除吗"></a>那你还懂标记清除吗</h3><h3 id="分代回收"><a href="#分代回收" class="headerlink" title="分代回收"></a>分代回收</h3><h2 id="引用计数："><a href="#引用计数：" class="headerlink" title="引用计数："></a>引用计数：</h2><pre><code>--如age=18
变量值18被关联了一个变量名age，引用计数+1</code></pre>
<h2 id="如何使引用计数减少-1"><a href="#如何使引用计数减少-1" class="headerlink" title="如何使引用计数减少:"></a>如何使引用计数减少:</h2><pre><code>--本来age=18
现在age=10
引用计数-1
当一个对象的引用被销毁时，对象的引用计数减1
当它引用计数为0时，就会被回收，释放内存</code></pre>
<h2 id="引用计数会导致什么问题："><a href="#引用计数会导致什么问题：" class="headerlink" title="引用计数会导致什么问题："></a>引用计数会导致什么问题：</h2><pre><code>--两个对象相互引用，引用计数不会为0
解决方法：py中的循环引用有标记-清除机制可以处理</code></pre>
<h2 id="那你还懂标记清除吗："><a href="#那你还懂标记清除吗：" class="headerlink" title="那你还懂标记清除吗："></a>那你还懂标记清除吗：</h2><pre><code>--标记：标记对象（垃圾检测）
--清除：清除垃圾（垃圾回收）</code></pre>
<h2 id="分代回收："><a href="#分代回收：" class="headerlink" title="分代回收："></a>分代回收：</h2><pre><code>--以空间换时间的技术
对象存在时间越长，就越不是垃圾，应该减少去收集
分代是解决内存遍历需要太长时间而诞生的
分代回收减少 标记清除机制所带来的额外操作
青年代   中年代   老年代</code></pre>

      
    </div>

    
    
    

    <footer class="post-footer">
        <div class="post-eof"></div>
      
    </footer>
  </article>
</div>




    


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="">
    <link itemprop="mainEntityOfPage" href="https://single-flower.gitee.io/wow/2021/04/08/SD/%E9%9D%A2%E8%AF%95%E9%A2%98_%E8%AF%AD%E6%B3%95%E5%9F%BA%E7%A1%802/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/wow/images/avatar.gif">
      <meta itemprop="name" content="X y">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="朵朵最可爱">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          <a href="/wow/2021/04/08/SD/%E9%9D%A2%E8%AF%95%E9%A2%98_%E8%AF%AD%E6%B3%95%E5%9F%BA%E7%A1%802/" class="post-title-link" itemprop="url">语法基础2</a>
        </h2>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">نُشر في</span>

      <time title="أُنشأ: 2021-04-08 19:44:06" itemprop="dateCreated datePublished" datetime="2021-04-08T19:44:06+08:00">2021-04-08</time>
    </span>
      <span class="post-meta-item">
        <span class="post-meta-item-icon">
          <i class="far fa-calendar-check"></i>
        </span>
        <span class="post-meta-item-text">عُدل في</span>
        <time title="عُدل: 2021-04-15 19:31:47" itemprop="dateModified" datetime="2021-04-15T19:31:47+08:00">2021-04-15</time>
      </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">في</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/wow/categories/GIT/" itemprop="url" rel="index"><span itemprop="name">-GIT</span></a>
        </span>
    </span>

  
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
          <h3 id="is和-的区别"><a href="#is和-的区别" class="headerlink" title="is和==的区别"></a>is和==的区别</h3><h3 id="range和xrange的区别"><a href="#range和xrange的区别" class="headerlink" title="range和xrange的区别"></a>range和xrange的区别</h3><h3 id="三元表达式"><a href="#三元表达式" class="headerlink" title="三元表达式"></a>三元表达式</h3><h3 id="不使用第三变量，实现两数交换"><a href="#不使用第三变量，实现两数交换" class="headerlink" title="不使用第三变量，实现两数交换"></a>不使用第三变量，实现两数交换</h3><h3 id="深浅拷贝"><a href="#深浅拷贝" class="headerlink" title="深浅拷贝"></a>深浅拷贝</h3><h3 id="python的自省"><a href="#python的自省" class="headerlink" title="python的自省"></a>python的自省</h3><h2 id="is和-的区别："><a href="#is和-的区别：" class="headerlink" title="is和==的区别："></a>is和==的区别：</h2><pre><code>--is：看两个实例对象是否完全一样，占用内存地址是否相同。
--==：两个对象的内容相等就行。</code></pre>
<h2 id="range和xrange的区别-1"><a href="#range和xrange的区别-1" class="headerlink" title="range和xrange的区别:"></a>range和xrange的区别:</h2><pre><code>--range返回的是一个list对象
--xrange返回的是一个迭代器对象</code></pre>
<h2 id="三元表达式："><a href="#三元表达式：" class="headerlink" title="三元表达式："></a>三元表达式：</h2><pre><code>三元表达式的格式为：条件表达式？结果1：结果2</code></pre>
<h2 id="不使用第三变量，实现两数交换："><a href="#不使用第三变量，实现两数交换：" class="headerlink" title="不使用第三变量，实现两数交换："></a>不使用第三变量，实现两数交换：</h2><p>1） 算术运算</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">int a,b;</span><br><span class="line">a=<span class="number">10</span>;b=<span class="number">12</span>;</span><br><span class="line">a=b-a; <span class="comment">//a=2;b=12</span></span><br><span class="line">b=b-a; <span class="comment">//a=2;b=10</span></span><br><span class="line">a=b+a; <span class="comment">//a=10;b=10</span></span><br></pre></td></tr></table></figure>

<h2 id="深浅拷贝："><a href="#深浅拷贝：" class="headerlink" title="深浅拷贝："></a>深浅拷贝：</h2><pre><code>--浅拷贝：只拷贝第一层，并没有拷贝深层次，修改第一层不改变，修改深层就相互影响了。
--深拷贝：递归性质的浅拷贝，它会在内存中生成一套完全一样的内容。修改其中一个变量，不会影响另一个。</code></pre>
<h2 id="python的自省："><a href="#python的自省：" class="headerlink" title="python的自省："></a>python的自省：</h2><pre><code>--自省就是一种自我检查的行为
就是面向对象的语言所写的程序在运行时，能够知道对象的类型</code></pre>

      
    </div>

    
    
    

    <footer class="post-footer">
        <div class="post-eof"></div>
      
    </footer>
  </article>
</div>




    


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="">
    <link itemprop="mainEntityOfPage" href="https://single-flower.gitee.io/wow/2021/04/06/SD/%E9%9D%A2%E8%AF%95%E9%A2%98_%E8%AF%AD%E8%A8%80%E7%9B%B8%E5%85%B31/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/wow/images/avatar.gif">
      <meta itemprop="name" content="X y">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="朵朵最可爱">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          <a href="/wow/2021/04/06/SD/%E9%9D%A2%E8%AF%95%E9%A2%98_%E8%AF%AD%E8%A8%80%E7%9B%B8%E5%85%B31/" class="post-title-link" itemprop="url">语言相关1</a>
        </h2>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">نُشر في</span>

      <time title="أُنشأ: 2021-04-06 21:34:08" itemprop="dateCreated datePublished" datetime="2021-04-06T21:34:08+08:00">2021-04-06</time>
    </span>
      <span class="post-meta-item">
        <span class="post-meta-item-icon">
          <i class="far fa-calendar-check"></i>
        </span>
        <span class="post-meta-item-text">عُدل في</span>
        <time title="عُدل: 2021-04-14 20:50:44" itemprop="dateModified" datetime="2021-04-14T20:50:44+08:00">2021-04-14</time>
      </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">في</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/wow/categories/GIT/" itemprop="url" rel="index"><span itemprop="name">-GIT</span></a>
        </span>
    </span>

  
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
          <h3 id="解释型和编译型语言的区别"><a href="#解释型和编译型语言的区别" class="headerlink" title="解释型和编译型语言的区别"></a>解释型和编译型语言的区别</h3><h3 id="列举几个p2和p3的区别"><a href="#列举几个p2和p3的区别" class="headerlink" title="列举几个p2和p3的区别"></a>列举几个p2和p3的区别</h3><h3 id="列举几个解释器的种类和特点"><a href="#列举几个解释器的种类和特点" class="headerlink" title="列举几个解释器的种类和特点"></a>列举几个解释器的种类和特点</h3><h3 id="PEP8规范"><a href="#PEP8规范" class="headerlink" title="PEP8规范"></a>PEP8规范</h3><h3 id="常见编码有哪些"><a href="#常见编码有哪些" class="headerlink" title="常见编码有哪些"></a>常见编码有哪些</h3><h2 id="解释型和编译型语言的区别-1"><a href="#解释型和编译型语言的区别-1" class="headerlink" title="解释型和编译型语言的区别:"></a>解释型和编译型语言的区别:</h2><pre><code>--解释型语言：python、JavaScript、PHP、Shell、MATLAB等
--解释型语言就是不用对源代码进行编译，通过解释器一边执行一边转换，需要哪些源代码就转换哪些，不生产可执行程序。
--转换的工具叫做解释器
总结：写代码的效率高，调bug比较容易，跨平台性很棒；但是执行效率不行。


--编译型语言：C、C++、Golang、Pascal(Delphi)、汇编等
--写完后需要打包和编译，打包后就省事了，随时都可使用
--它必须要求必须提前将所有的源代码一次性转换为二进制指令，生成一个可执行程序
--所使用的工具叫做编译器
--需在Linux下安装程序时需要GCC或G++
总结：执行效率高，但是调bug很麻烦</code></pre>
<h2 id="列举几个p2和p3的区别-1"><a href="#列举几个p2和p3的区别-1" class="headerlink" title="列举几个p2和p3的区别:"></a>列举几个p2和p3的区别:</h2><h2 id="列举几个解释器的种类和特点："><a href="#列举几个解释器的种类和特点：" class="headerlink" title="列举几个解释器的种类和特点："></a>列举几个解释器的种类和特点：</h2><pre><code>--CPython:c语言开发的，是使用最广的解释器，具有GIL全局解释器锁
--IPython:基于CPython的交互式解释器，功能与CPython无异</code></pre>
<h2 id="PEP8规范："><a href="#PEP8规范：" class="headerlink" title="PEP8规范："></a>PEP8规范：</h2><pre><code>1、每个 import 语句只导入一个模块，尽量避免一次导入多个模块
2、不要在行尾添加分号，也不要用分号将两条命令放在同一行

3、建议每行不超过 80 个字符，如果超过，建议使用小括号将多行内容隐式的连接起来，而不推荐使用反斜杠 \ 进行连接。
4、通常情况下，在运算符两侧、函数参数之间以及逗号两侧，都建议使用空格进行分隔。</code></pre>
<h2 id="常见编码有哪些："><a href="#常见编码有哪些：" class="headerlink" title="常见编码有哪些："></a>常见编码有哪些：</h2><pre><code>--ASCII编码：用来表示英文，它使用1个字节表示，其中第一位规定为0，其他7位存储数据，一共可以表示128个字符。

--拓展ASCII编码：用于表示更多的欧洲文字，用8个位存储数据，一共可以表示256个字符

--GBK/GB2312/GB18030：表示汉字。GBK/GB2312表示简体中文，GB18030表示繁体中文。

--Unicode编码：包含世界上所有的字符，是一个字符集。

--UTF-8：是Unicode字符的实现方式之一，它使用1-4个字符表示一个符号，根据不同的符号而变化字节长度。</code></pre>

      
    </div>

    
    
    

    <footer class="post-footer">
        <div class="post-eof"></div>
      
    </footer>
  </article>
</div>




    


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="">
    <link itemprop="mainEntityOfPage" href="https://single-flower.gitee.io/wow/2021/02/18/zy/docker%E6%93%8D%E4%BD%9C%E5%AE%B9%E5%99%A8%EF%BC%8C%E9%95%9C%E5%83%8F/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/wow/images/avatar.gif">
      <meta itemprop="name" content="X y">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="朵朵最可爱">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          <a href="/wow/2021/02/18/zy/docker%E6%93%8D%E4%BD%9C%E5%AE%B9%E5%99%A8%EF%BC%8C%E9%95%9C%E5%83%8F/" class="post-title-link" itemprop="url">docker操作容器，镜像</a>
        </h2>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">نُشر في</span>

      <time title="أُنشأ: 2021-02-18 18:53:19" itemprop="dateCreated datePublished" datetime="2021-02-18T18:53:19+08:00">2021-02-18</time>
    </span>
      <span class="post-meta-item">
        <span class="post-meta-item-icon">
          <i class="far fa-calendar-check"></i>
        </span>
        <span class="post-meta-item-text">عُدل في</span>
        <time title="عُدل: 2021-04-13 15:05:37" itemprop="dateModified" datetime="2021-04-13T15:05:37+08:00">2021-04-13</time>
      </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">في</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/wow/categories/GIT/" itemprop="url" rel="index"><span itemprop="name">-GIT</span></a>
        </span>
    </span>

  
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
          <h2 id="什么是docker"><a href="#什么是docker" class="headerlink" title="什么是docker"></a>什么是docker</h2><p>Docker 是一个开源的应用容器引擎，让开发者可以打包他们的应用以及依赖包到一个可移植的镜像中，然后发布到任何流行的 Linux或Windows 机器上，也可以实现虚拟化。容器是完全使用沙箱机制，相互之间不会有任何接口</p>
<h2 id="docker-优点"><a href="#docker-优点" class="headerlink" title="docker-优点"></a>docker-优点</h2><p>快速部署：短时间内可以部署成百上千个应⽤，更快速交付到线上<br>⾼效虚拟化：不需要额外hypervisor⽀持，基于linux内核实现应⽤虚拟化，相⽐虚拟机⼤幅提⾼<br>性能和效率<br>节省开⽀：提⾼服务器利⽤率，降低IT⽀出<br>简化配置：将运⾏环境打包保存⾄容器，使⽤时直接启动即可<br>环境统⼀：将开发，测试，⽣产的应⽤运⾏环境进⾏标准化和统⼀，减少环境不⼀样带来的各种问<br>题<br>快速迁移和扩展：可实现跨平台运⾏在物理机、虚拟机、公有云等环境，良好的兼容性可以⽅便将<br>应⽤从A宿主机迁移到B宿主机，甚⾄是A平台迁移到B平台</p>
<h2 id="docker-三个基本概念"><a href="#docker-三个基本概念" class="headerlink" title="docker-三个基本概念"></a>docker-三个基本概念</h2><h3 id="Image-镜像"><a href="#Image-镜像" class="headerlink" title="Image(镜像)"></a>Image(镜像)</h3><p>Docker 镜像就是一个只读的模板，镜像可以用来创建 Docker 容器。Docker 提供了一个很简单的机制来创建镜像或者更新现有的镜像，用户甚至可以直接从其他人那里下载一个已经做好的镜像来直接使用。镜像是一种文件结构。Dockerfile中的每条命令都会在文件系统中创建一个新的层次结构，文件系统在这些层次上构建起来，镜像就构建于这些联合的文件系统之上。Docker官方网站专门有一个页面来存储所有可用的镜像，网址是：index.docker.io</p>
<h3 id="Container-容器"><a href="#Container-容器" class="headerlink" title="Container(容器)"></a>Container(容器)</h3><p>容器是从镜像创建的运行实例。它可以被启动、开始、停止、删除。每个容器都是相互隔离的、保证安全的平台。可以把容器看做是一个简易版的 Linux 环境，Docker 利用容器来运行应用</p>
<h3 id="Repository-仓库"><a href="#Repository-仓库" class="headerlink" title="Repository(仓库)"></a>Repository(仓库)</h3><p>public(公有仓库) private(私有仓库)<br>仓库是集中存放镜像文件的场所，仓库注册服务器（Registry）上往往存放着多个仓库，每个仓库中又包含了多个镜像，每个镜像有不同的标签（tag）。目前，最大的公开仓库是 Docker Hub，存放了数量庞大的镜像供用户下载</p>
<h2 id="docker-镜像"><a href="#docker-镜像" class="headerlink" title="docker-镜像"></a>docker-镜像</h2><h3 id="常用命令"><a href="#常用命令" class="headerlink" title="常用命令"></a>常用命令</h3><h2 id="操作-命令"><a href="#操作-命令" class="headerlink" title="操作        命令"></a>操作        命令</h2><p>搜索镜像    docker search [OPTIONS] 镜像名称<br>上传镜像    docker push [OPTIONS] NAME[:TAG]<br>下载镜像    docker pull [OPTIONS] NAME[:TAG]<br>提交镜像    docker commit [OPTIONS] CONTAINER NAME[:TAG]<br>构建镜像    docker build [OPTIONS] PATH<br>增加镜像标签    docker tag SOURCE_IMAGE[:TAG] TARGET_IMAGE[:TAG]<br>查看本地所有镜像    docker images [OPTIONS] [REPOSITORY[:TAG]]<br>删除指定的本地镜像    docker rmi [OPTIONS] IMAGE [IMAGE…]</p>
<p>常用操作</p>
<h3 id="检测云端镜像"><a href="#检测云端镜像" class="headerlink" title="检测云端镜像"></a>检测云端镜像</h3><p>docker search 关键字<br>如检索 “ mysql “：[root@localhost ~]# docker search mysql</p>
<h3 id="下载镜像"><a href="#下载镜像" class="headerlink" title="下载镜像"></a>下载镜像</h3><p>docker pull 镜像名称:tag<br>“ :tag ” 不写时默认下载最新版本的镜像，也可以自己指定 tag 从而下载指定版本的镜像，tag 名称可以从 Docker Hub 上自己查看</p>
<h3 id="查看本地镜像"><a href="#查看本地镜像" class="headerlink" title="查看本地镜像"></a>查看本地镜像</h3><p>docker images</p>
<h3 id="删除镜像"><a href="#删除镜像" class="headerlink" title="删除镜像"></a>删除镜像</h3><p>docker rmi image-id</p>
<h2 id="docker-容器"><a href="#docker-容器" class="headerlink" title="docker-容器"></a>docker-容器</h2><p>软件镜像(Images)启动之后就会有一个对应的容器(Container)，镜像位于自己的容器中，容器之间相互隔离</p>
<h3 id="常用命令-1"><a href="#常用命令-1" class="headerlink" title="常用命令"></a>常用命令</h3><h2 id="操作-命令-1"><a href="#操作-命令-1" class="headerlink" title="操作        命令"></a>操作        命令</h2><p>运行容器    docker run –name container-name -d image-name:tag<br>启动容器    docker start container-name/container-id<br>重启容器    docker restart container-name/container-id<br>查看容器列表    docker ps [option]<br>停止容器    docker stop container-name/container-id<br>删除容器    docker rm container-id<br>重命名容器    docker rename CONTAINER CONTAINER_NEW<br>进入容器    docker attach CONTAINER<br>执行容器命令    docker exec CONTAINER COMMAND<br>端口映射    docker run –name myredis -d -p 6379:6379 docker.io/redis<br>查看容器日志    docker logs container-name/container-id</p>
<h2 id="常用操作"><a href="#常用操作" class="headerlink" title="常用操作"></a>常用操作</h2><h3 id="查看容器"><a href="#查看容器" class="headerlink" title="查看容器"></a>查看容器</h3><p>docker ps<br>加上 -a 参数可以查看所有容器</p>
<h3 id="运行容器"><a href="#运行容器" class="headerlink" title="运行容器"></a>运行容器</h3><p>docker run –name container-name:tag -d image-name<br>–name：自定义容器名，不指定时，docker 会自动生成一个名称<br>-d：表示后台运行容器<br>image-name：指定运行的镜像名称以及 Tag</p>
<h3 id="停止容器"><a href="#停止容器" class="headerlink" title="停止容器"></a>停止容器</h3><p>docker stop container-name|container-id<br>指定容器名或者容器 id 即可</p>
<h3 id="启动容器"><a href="#启动容器" class="headerlink" title="启动容器"></a>启动容器</h3><p>docker start container-name|container-id<br>指定容器名或者容器 id 即可</p>
<h3 id="删除容器"><a href="#删除容器" class="headerlink" title="删除容器"></a>删除容器</h3><p>docker rm container-id<br>根据 容器 id 进行删除容器，删除前必须先停止容器</p>
<h3 id="查看容器日志"><a href="#查看容器日志" class="headerlink" title="查看容器日志"></a>查看容器日志</h3><p>docker logs container-name|container-id<br>指定容器名或者容器 id 即可</p>
<h2 id="什么是dockerfile"><a href="#什么是dockerfile" class="headerlink" title="什么是dockerfile"></a>什么是dockerfile</h2><p>Dockerfile 是自动构建 docker 镜像的配置文件， 用户可以使用 Dockerfile 快速创建自定义的镜像。Dockerfile 中的命令非常类似于 linux 下的 shell 命令<br>Dockerfile 可以自定义镜像，通过 Docker 命令去运行镜像，从而达到启动容器的目的</p>
<h2 id="dockerfile基本结构"><a href="#dockerfile基本结构" class="headerlink" title="dockerfile基本结构"></a>dockerfile基本结构</h2><p>基础镜像(父镜像)信息指令 FROM<br>维护者信息指令 MAINTAINER<br>镜像操作指令 RUN 、 EVN 、 ADD 和 WORKDIR 等<br>容器启动指令 CMD 、 ENTRYPOINT 和 USER 等</p>
<h2 id="dockerfile常用指令"><a href="#dockerfile常用指令" class="headerlink" title="dockerfile常用指令"></a>dockerfile常用指令</h2><p>Dockerfile 的指令每执⾏⼀次都会在 docker 上新建⼀层。所以过多⽆意义的层，会造成镜像膨胀 过⼤</p>
<h3 id="FROM"><a href="#FROM" class="headerlink" title="FROM"></a>FROM</h3><p>定制镜像，需要先有⼀个基础镜像，在这个基础镜像上进⾏定制。FROM 就是指定基础镜像，此<br>指令必需放在有效指令的第⼀⾏</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">FROM nginx</span><br><span class="line">RUN echo <span class="string">&#x27;这是⼀个本地构建的nginx镜像&#x27;</span> &gt; <span class="regexp">/usr/</span>share/nginx/html/index.html</span><br></pre></td></tr></table></figure>
<h3 id="LABEL"><a href="#LABEL" class="headerlink" title="LABEL"></a>LABEL</h3><p>可以指定镜像元数据，如：镜像作者等</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">LABEL &lt;key&gt;=&lt;value&gt; &lt;key&gt;=&lt;value&gt; ...</span><br></pre></td></tr></table></figure>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">LABEL version=<span class="string">&quot;1.0&quot;</span></span><br><span class="line">LABEL description=<span class="string">&#x27;this is a content&#x27;</span></span><br></pre></td></tr></table></figure>
<h3 id="RUN"><a href="#RUN" class="headerlink" title="RUN"></a>RUN</h3><p>⽤来执⾏命令、RUN 指令经常⽤来调⽤shell指令<br>注意：run可以写多个，每⼀个run指令都会建⽴⼀层，所以尽可能合并成⼀条指令</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">RUN &lt;命令&gt;</span><br><span class="line">RUN [<span class="string">&quot;可执⾏⽂件&quot;</span>,<span class="string">&quot;参数1&quot;</span>,<span class="string">&quot;参数2&quot;</span>]</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">RUN echo <span class="string">&quot;hello world&quot;</span> &gt; <span class="regexp">/usr/</span>share/nginx/html/index.html</span><br><span class="line">RUN yum install epel-release \</span><br><span class="line"> &amp;&amp; yum install nginx \</span><br><span class="line"> &amp;&amp; yum install mysql</span><br><span class="line"></span><br><span class="line">k</span><br><span class="line">RUN [<span class="string">&quot;/usr/bin/python3&quot;</span>,<span class="string">&quot;1.py&quot;</span>]</span><br></pre></td></tr></table></figure>
      
    </div>

    
    
    

    <footer class="post-footer">
        <div class="post-eof"></div>
      
    </footer>
  </article>
</div>




    


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="">
    <link itemprop="mainEntityOfPage" href="https://single-flower.gitee.io/wow/2021/02/18/zy/%E8%A7%86%E9%A2%91%E7%9B%B4%E6%92%AD/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/wow/images/avatar.gif">
      <meta itemprop="name" content="X y">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="朵朵最可爱">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          <a href="/wow/2021/02/18/zy/%E8%A7%86%E9%A2%91%E7%9B%B4%E6%92%AD/" class="post-title-link" itemprop="url">视频直播</a>
        </h2>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">نُشر في</span>

      <time title="أُنشأ: 2021-02-18 18:40:59" itemprop="dateCreated datePublished" datetime="2021-02-18T18:40:59+08:00">2021-02-18</time>
    </span>
      <span class="post-meta-item">
        <span class="post-meta-item-icon">
          <i class="far fa-calendar-check"></i>
        </span>
        <span class="post-meta-item-text">عُدل في</span>
        <time title="عُدل: 2021-04-13 15:05:16" itemprop="dateModified" datetime="2021-04-13T15:05:16+08:00">2021-04-13</time>
      </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">في</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/wow/categories/GIT/" itemprop="url" rel="index"><span itemprop="name">-GIT</span></a>
        </span>
    </span>

  
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
          <h2 id="直播"><a href="#直播" class="headerlink" title="直播"></a>直播</h2><h3 id="直播：流式传输协议，传输非常短的一小截视频"><a href="#直播：流式传输协议，传输非常短的一小截视频" class="headerlink" title="直播：流式传输协议，传输非常短的一小截视频"></a>直播：流式传输协议，传输非常短的一小截视频</h3><h3 id="观看直播"><a href="#观看直播" class="headerlink" title="观看直播"></a>观看直播</h3><p>浏览器：video标签<br>客户端工具：vlc播放器</p>
<h3 id="协议"><a href="#协议" class="headerlink" title="协议"></a>协议</h3><p>rtmp协议</p>
<h3 id="推流（使用OBS）"><a href="#推流（使用OBS）" class="headerlink" title="推流（使用OBS）"></a>推流（使用OBS）</h3><p>将现场的视频信号传到网络的过程，对网络要求比较高<br>OBS下载地址：<a target="_blank" rel="noopener" href="https://obsproject.com/zh-cn">https://obsproject.com/zh-cn</a></p>
<h3 id="拉流（使用浏览器或Vlc）"><a href="#拉流（使用浏览器或Vlc）" class="headerlink" title="拉流（使用浏览器或Vlc）"></a>拉流（使用浏览器或Vlc）</h3><p>服务器已有直播内容，根据协议类型（如RTMP、RTP、RTSP、HTTP等），与服务器建立连接并接收数据，进行拉取的过程<br>Vlc下载地址：<a target="_blank" rel="noopener" href="https://www.videolan.org/vlc/">https://www.videolan.org/vlc/</a></p>
<h2 id="常见的直播协议"><a href="#常见的直播协议" class="headerlink" title="常见的直播协议"></a>常见的直播协议</h2><h3 id="RTMP直播协议"><a href="#RTMP直播协议" class="headerlink" title="RTMP直播协议"></a>RTMP直播协议</h3><p>RTMP 是专为流媒体开发的协议，对底层的优化比其它协议更加优秀</p>
<h3 id="优点"><a href="#优点" class="headerlink" title="优点"></a>优点</h3><p>它对 Adobe Flash 支持好<br>基本上所有的编码器（摄像头之类）都支持 RTMP 输出<br>另外RTMP适合长时间播放，即 10 天多连续播放没有出现问题，稳定<br>最后 RTMP 的延迟相对较低，一般延时在 1-3s 之间，一般的视频会议，互动式直播，完全是够用的</p>
<h3 id="缺点"><a href="#缺点" class="headerlink" title="缺点"></a>缺点</h3><p>它是基于 TCP 传输，非公共端口，可能会被防火墙阻拦<br>RTMP 为 Adobe 私有协议，很多设备无法播放，兼容性不高<br>Html基础支持不好，无法直接使用HTML标签完成拉流</p>
<h3 id="HTTP-FLV直播协议"><a href="#HTTP-FLV直播协议" class="headerlink" title="HTTP-FLV直播协议"></a>HTTP-FLV直播协议</h3><p>FLV: 简单轻量、加载速度极快、播放快</p>
<h3 id="优点-1"><a href="#优点-1" class="headerlink" title="优点"></a>优点</h3><p>可以直接通过http协议进行传输，http属于公共协议，公共端口：80<br>支持加密，使用https<br>兼容移动端设备，比如：安卓、ios</p>
<h3 id="缺点-1"><a href="#缺点-1" class="headerlink" title="缺点"></a>缺点</h3><p>会缓存直播数据，保存直播传输过来的一段段flv文件，隐私保密不好<br>不能在大并发情况下使用</p>
<h3 id="HLS直播协议"><a href="#HLS直播协议" class="headerlink" title="HLS直播协议"></a>HLS直播协议</h3><p>苹果公司实现的基于 HTTP 的流媒体传输协议</p>
<h3 id="优点-2"><a href="#优点-2" class="headerlink" title="优点"></a>优点</h3><p>数据通过 HTTP 协议传输，所以采用 HLS 时不用考虑防火墙或者代理的问题。<br>使用短时长的分片文件来播放，客户端可以平滑的切换码率，以适应不同带宽条件下的播放。<br>HLS 是苹果推出的流媒体协议，在 iOS 平台上可以获得天然的支持，采用系统提供的 AVPlayer 就能直接播放，不用自己开发播放器</p>
<h3 id="缺点-2"><a href="#缺点-2" class="headerlink" title="缺点"></a>缺点</h3><p>通常 HLS 直播延时会达到 20-30s，而高延时对于需要实时互动体验的直播来说是不可接受的。<br>HLS 基于短连接 HTTP，HTTP 是基于 TCP 的，这就意味着 HLS 需要不断地与服务器建立连接，TCP 每次建立连接时的三次握手、慢启动过程、断开连接时的四次挥手都会产生消耗</p>
<h2 id="云主机搭建直播"><a href="#云主机搭建直播" class="headerlink" title="云主机搭建直播"></a>云主机搭建直播</h2><h3 id="创建软件的存储位置"><a href="#创建软件的存储位置" class="headerlink" title="创建软件的存储位置"></a>创建软件的存储位置</h3><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">mkdir /usr/local/nginx-flv</span><br><span class="line"><span class="comment">// 创建了一个安装目录</span></span><br><span class="line">mkdir /home/flv-tools</span><br><span class="line"><span class="comment">// 存储所需软件</span></span><br></pre></td></tr></table></figure>
<h3 id="下载nginx"><a href="#下载nginx" class="headerlink" title="下载nginx"></a>下载nginx</h3><p>高性能多路复用服务器，让你支持同时响应多个客户连接<br>多线程、多进程开发模式<br>wget <a target="_blank" rel="noopener" href="https://nginx.org/download/nginx-1.18.0.tar.gz">https://nginx.org/download/nginx-1.18.0.tar.gz</a></p>
<h3 id="下载直播模块"><a href="#下载直播模块" class="headerlink" title="下载直播模块"></a>下载直播模块</h3><p>git clone <a target="_blank" rel="noopener" href="https://github.com/winshining/nginx-http-flv-module">https://github.com/winshining/nginx-http-flv-module</a></p>
<h3 id="解压下载好的nginx"><a href="#解压下载好的nginx" class="headerlink" title="解压下载好的nginx"></a>解压下载好的nginx</h3><p>tar -zxvf nginx-1.18.0.tar.gz nginx-1.18.0/</p>
<h3 id="解压下载好的rtmp直播模块"><a href="#解压下载好的rtmp直播模块" class="headerlink" title="解压下载好的rtmp直播模块"></a>解压下载好的rtmp直播模块</h3><p>unzip nginx-http-flv-module.zip</p>
<h3 id="进入解压好的nginx下目录，并进行安装前的配置"><a href="#进入解压好的nginx下目录，并进行安装前的配置" class="headerlink" title="进入解压好的nginx下目录，并进行安装前的配置"></a>进入解压好的nginx下目录，并进行安装前的配置</h3><p>cd nginx-1.18.0<br>./configure –prefix=/usr/local/nginx-flv –add-module=/home/flv-tools/nginx-http-flv-module-master<br>–prefix: 配置安装路径<br>–add-module: 添加安装插件</p>
<h3 id="编译及安装"><a href="#编译及安装" class="headerlink" title="编译及安装"></a>编译及安装</h3><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">make </span><br><span class="line">make install </span><br><span class="line">------------</span><br><span class="line">make &amp;&amp; make install </span><br></pre></td></tr></table></figure>
<h2 id="配置文件相关"><a href="#配置文件相关" class="headerlink" title="配置文件相关"></a>配置文件相关</h2><h3 id="修改配置文件"><a href="#修改配置文件" class="headerlink" title="修改配置文件"></a>修改配置文件</h3><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br></pre></td><td class="code"><pre><span class="line">worker_processes  <span class="number">1</span>;</span><br><span class="line"></span><br><span class="line">rtmp_auto_push on;</span><br><span class="line">rtmp_auto_push_reconnect 1s;</span><br><span class="line">rtmp_socket_dir /tmp;</span><br><span class="line"></span><br><span class="line">rtmp&#123;</span><br><span class="line">	out_queue <span class="number">4096</span>;</span><br><span class="line">	out_cork <span class="number">8</span>;</span><br><span class="line">	max_streams <span class="number">128</span>;</span><br><span class="line">	timeout 15s;</span><br><span class="line">	drop_idle_publisher 15s;</span><br><span class="line">	log_interval 5s;</span><br><span class="line">	log_size 1m;</span><br><span class="line">	server &#123;</span><br><span class="line">		listen 1935; # 推流端口</span><br><span class="line">		server_name zege;</span><br><span class="line">		</span><br><span class="line">		application live &#123;	# 配置推流地址</span><br><span class="line">			live on; # 打开推流</span><br><span class="line">			# gop_cache on;</span><br><span class="line">			# rtmp://123.123.123.123:1935/live/test</span><br><span class="line">		&#125;</span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">events &#123;</span><br><span class="line">    worker_connections  <span class="number">1024</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h3 id="配置文件http拉流部分"><a href="#配置文件http拉流部分" class="headerlink" title="配置文件http拉流部分"></a>配置文件http拉流部分</h3><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line">http &#123;</span><br><span class="line">	include       mime.types;</span><br><span class="line">	default_type  application/octet-stream;</span><br><span class="line">	sendfile        on;</span><br><span class="line">	keepalive_timeout  <span class="number">65</span>;</span><br><span class="line">	server &#123;</span><br><span class="line">		listen       8080; # 拉流通过8080去拉流</span><br><span class="line">		# http://123.123.123.123:8080/live/?port=1935&amp;stream=test</span><br><span class="line">		server_name  localhost;</span><br><span class="line">		location /live &#123;</span><br><span class="line">			flv_live on;</span><br><span class="line">			chunked_transfer_encoding  on;</span><br><span class="line">			add_header <span class="string">&#x27;Access-Control-Allow-Origin&#x27;</span> <span class="string">&#x27;*&#x27;</span>;</span><br><span class="line">			add_header <span class="string">&#x27;Access-Control-Allow-Credentials&#x27;</span> <span class="string">&#x27;true&#x27;</span>;</span><br><span class="line">		&#125;</span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h2 id="服务相关"><a href="#服务相关" class="headerlink" title="服务相关"></a>服务相关</h2><h3 id="关闭旧有服务"><a href="#关闭旧有服务" class="headerlink" title="关闭旧有服务"></a>关闭旧有服务</h3><p>/usr/local/nginx-rtmp/sbin/nginx -s stop<br>/usr/local/nginx-rtmp/sbin/nginx -s reload<br>重启</p>
<h3 id="开启新服务"><a href="#开启新服务" class="headerlink" title="开启新服务"></a>开启新服务</h3><p>/usr/local/nginx-flv/sbin/nginx -c /usr/local/nginx-flv/conf/nginx.conf<br>记得打开阿里云的防火墙哦</p>
<h2 id="推拉流地址"><a href="#推拉流地址" class="headerlink" title="推拉流地址"></a>推拉流地址</h2><h3 id="推流地址"><a href="#推流地址" class="headerlink" title="推流地址"></a>推流地址</h3><p>rtmp://云主机的ip:端口/live/密钥</p>
<h3 id="拉流地址"><a href="#拉流地址" class="headerlink" title="拉流地址"></a>拉流地址</h3><p>http://云主机的ip:8080/live?port=端口&amp;app=live&amp;stream=密钥</p>

      
    </div>

    
    
    

    <footer class="post-footer">
        <div class="post-eof"></div>
      
    </footer>
  </article>
</div>




  <nav class="pagination">
    <span class="page-number current">1</span><a class="page-number" href="/wow/page/2/">2</a><a class="page-number" href="/wow/page/3/">3</a><a class="extend next" rel="next" href="/wow/page/2/"><i class="fa fa-angle-right" aria-label="الصفحة التالية"></i></a>
  </nav>


<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      const activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      const commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>
</div>
  </main>

  <footer class="footer">
    <div class="footer-inner">


<div class="copyright">
  &copy; 
  <span itemprop="copyrightYear">2021</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">X y</span>
</div>
  <div class="powered-by">تطبيق الموقع <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> & <a href="https://theme-next.js.org/muse/" class="theme-link" rel="noopener" target="_blank">NexT.Muse</a>
  </div>

    </div>
  </footer>

  
  <script src="https://cdn.jsdelivr.net/npm/animejs@3.2.1/lib/anime.min.js"></script>
<script src="/wow/js/utils.js"></script><script src="/wow/js/motion.js"></script><script src="/wow/js/schemes/muse.js"></script><script src="/wow/js/next-boot.js"></script>

  






  





</body>
</html>
